<?php

class User extends CActiveRecord
{
	var $userName;
	var $firstName;
	var $lastName;
	/**
	 * The followings are the available columns in table 'users':
	 * @var integer $id
	 * @var string $userName
	 * @var string $firstName
	 * @var string $lastName
	 * @var string $password
	 * @var string $email
	 * @var integer $role
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return Yii::app()->getModule('user')->tableUsers;
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return (array(
			array('userName', 'length', 'max'=>20, 'min' => 3,'message' => UserModule::t("Incorrect userName (length between 3 and 20 characters).")),
			array('firstName', 'length', 'max'=>20, 'min' => 3,'message' => UserModule::t("Incorrect userName (length between 3 and 20 characters).")),
			array('lastName', 'length', 'max'=>20, 'min' => 3,'message' => UserModule::t("Incorrect userName (length between 3 and 20 characters).")),
			array('role', 'length', 'max'=>20, 'min' => 3,'message' => UserModule::t("Incorrect userName (length between 3 and 20 characters).")),
			array('password', 'length', 'max'=>128, 'min' => 4,'message' => UserModule::t("Incorrect password (minimal length 4 symbols).")),
			array('email', 'email'),
			array('userName', 'unique', 'message' => UserModule::t("This user's name already exists.")),
			array('email', 'unique', 'message' => UserModule::t("This user's email address already exists.")),
			array('userName', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u','message' => UserModule::t("Incorrect symbols (A-z0-9).")),
			array('userName, email', 'required'),
		));
	}
/*
	public function relations()
	{
		return false;
	}
*/
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'userName'=>UserModule::t("User name"),
			'firstName'=>UserModule::t("First name"),
			'lastName'=>UserModule::t("Last name"),
			'password'=>UserModule::t("Password"),
			'email'=>UserModule::t("E-mail"),
			'id' => UserModule::t("Id"),
			'role' => UserModule::t("Role"),
		);
	}
	
	public function scopes()
	{
			return array(
					'notsafe'=>array(
						'select' => 'id, firstName, lastName, userName, password, email, role',
					),
			);
	}
	
	public function defaultScope()
    {
        return array(
            'select' => 'id, firstName, lastName, userName, email, role',
        );
    }
	
	public static function itemAlias($type,$code=NULL) {
			return  false;
	}
}